package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

public class PaymentMethodAttrHandler extends AbstractAttrHandler<KiteProdInst, AttrData> {

    @Autowired
    IOperateSceneInstService operateSceneInstService;

    @Override
    public void before(KiteAttr attr, KiteProdInst inst, String value, AttrData data) {
        // 付费周期
       /* KiteAttr payCycleAttr = inst.getAttr("200002802");
        if (Objects.nonNull(payCycleAttr)) {

            //“付费方式”选择“后付费”时，付费周期只能选择“月付”；
            //“付费方式”选择“预付费”时，付费周期三个选项都可以选择；

           /** List<KiteAttrValue> payCycleAttrValues = payCycleAttr.getAttrValues();
            if (KiteStringUtils.equals("100001377", value)) {
                payCycleAttrValues.removeIf(payCycleAttrValue -> KiteStringUtils.equalsAny(payCycleAttrValue.getAttrValue(), "100004660", "100004662"));
                if (KiteStringUtils.equalsAny(payCycleAttr.getValue(), "100004660", "100004662")) {
                    payCycleAttr.setValue("");
                    payCycleAttr.setValueDesc("");
                    payCycleAttr.setDefaultValue("");
                }
                operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), payCycleAttr);
            } else if (KiteStringUtils.equals("100001718", value)) {
                List<AttrValue> attrValues = AttrValueCache.get(payCycleAttr.getAttrId());
                if (CollectionUtils.isNotEmpty(attrValues)) {
                    payCycleAttr.setAttrValues(KiteBeanUtils.copyPropsForList(attrValues, KiteAttrValue.class));
                    operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), payCycleAttr);
                }
            }
        }*/
    }
}
